package io;

import java.io.*;

public class OutStreamTest {
    public static void main(String[] args) {
//        try {
//            byte bWrite[] = { 11, 21, 31, 41, 5 };
//            OutputStream os = new FileOutputStream("tmp\\test.txt");
//            for (int i = 0; i < bWrite.length; i ++){
//                os.write(bWrite[i]);//write the bytes
//            }
//            os.close();
//
//            InputStream is = new FileInputStream("tmp\\test.txt");
//            int size = is.available();
//            for (int x = 0; x < size; x++){
//                System.out.println((char) is.read() + " ");
//            }
//            is.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//            System.out.println("Exception io");
//        }

        try {
            File f = new File("tmp\\a.txt");
//            FileOutputStream fos = new FileOutputStream(f);
//            OutputStreamWriter writer = new OutputStreamWriter(fos, "UTF-8");
//            writer.append("中文输入");
//            writer.append("\r\n");
//            writer.append("English0");
//            writer.close();
//            fos.close();

            FileInputStream fis = new FileInputStream(f);
            InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
            StringBuffer sb = new StringBuffer();
            while (reader.ready()){
                sb.append((char) reader.read());
            }
            System.out.println(sb.toString());
            reader.close();
            fis.close();
        } catch (IOException e){
            e.printStackTrace();
        }
    }
}
